use std::net::Ipv4Addr;
use std::net::SocketAddrV4;
use std::sync::Arc;

use anyhow::Result;
use apikit::doc::ApiDocumentCollector;
use apikit::mock::mocker::DefalutMocker;
use apikit::mock::mocker::MockOptions;
use carpet::mock::server::MockServer;
use carpet::mock::server::MockState;
use carpet::server::Server;
use carpet::server::init_log;
use log::info;
use server::DemoServer;
pub mod api;
pub mod server;

#[tokio::main]
async fn main() -> Result<()> {
    let _guard = init_log(None, None)?;
    let document = ApiDocumentCollector::document();
    for operation in &document.operations {
        info!("{} - {}", operation.method, operation.path);
    }

    let document = Arc::new(document);
    let mocker = MockServer {
        addr: std::net::SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::from([0, 0, 0, 0]), 8031)),
        state: MockState {
            mocker: Arc::new(DefalutMocker::new(document.clone())),
            document,
            options: MockOptions {
                max_recursion: 20,
                serilaize: true,
            },
        },
    };
    let mocker = mocker.run();

    let server = DemoServer {};
    let server = server.run();

    let _ = tokio::join!(server, mocker);

    Ok(())
}
